package com.thingcom.delinrobot.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.thingcom.delinrobot.R;
import com.thingcom.delinrobot.utils.ToastUtil;
import com.thingcom.delinrobot.view.SimpleToolbar;

import butterknife.Unbinder;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * author : YuFeng
 * e-mail : 923462992@qq.com
 * date   : 2019/11/4
 */
public class BaseMainFragment extends SupportFragment {
    private static final String TAG = "BaseMainFragment";
    // 再点一次退出程序时间设置
    private static final long WAIT_TIME = 2000L;
    private long TOUCH_TIME = 0;

//    protected OnFragmentOpenDrawerListener mOpenDraweListener;
    protected Unbinder unbinder;


    @Override
    public boolean onBackPressedSupport() {
        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME){
            _mActivity.finish();
        }else {
            TOUCH_TIME = System.currentTimeMillis();
            ToastUtil.showToast(_mActivity,getString(R.string.toast_press_again_exit));
        }
        return true;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
//    protected void initToolbarNav(Toolbar toolbar) {
//        initToolbarNav(toolbar, false);
//    }

    protected void initToolbar(SimpleToolbar toolbar){
//        if (mOpenDraweListener != null) {
//            mOpenDraweListener.onLockedDrawer();
//        }
        toolbar.setMyLeftIcon(R.drawable.menu);
        toolbar.setMinimumHeight(42);
        toolbar.setBackgroundColor(getResources().getColor(R.color.black_main));
        toolbar.setTitleStyle(getResources().getColor(R.color.white_main),20);
        toolbar.setLeftIconClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                if (mOpenDraweListener != null) {
//                    mOpenDraweListener.onOpenDrawer();
//                }
            }
        });

    }

//    protected void initToolbarNav(Toolbar toolbar, boolean isHome) {
//        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
//        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mOpenDraweListener != null) {
//                    mOpenDraweListener.onOpenDrawer();
//                }
//            }
//        });
//    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
//        if (context instanceof OnFragmentOpenDrawerListener) {
//            mOpenDraweListener = (OnFragmentOpenDrawerListener) context;
//        } else {
////            throw new RuntimeException(context.toString()
////                    + " must implement OnFragmentOpenDrawerListener");
//        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
//        mOpenDraweListener = null;
    }

//    public interface OnFragmentOpenDrawerListener {
//        void onOpenDrawer();
//        void onLockedDrawer();
//    }
//
//    protected void lockDrawer(){
//        mOpenDraweListener.onLockedDrawer();
//    }
}
